// pages/record/record.js
Page({

    data: {
        listIndex:[],
        reverselist:[],
        list:[]
    },
    onLoad: function (options) {
        var that = this;
        wx.request({
          url: 'https://api.heclouds.com/devices/719570442/datapoints',
          data: {
            datastream_id: 'timer',
            start: '2021-07-08T21:34:00',
            sort:'DESC'
          },
          header: {
            'content-type': 'application/json',
            'Authorization':'version=2018-10-31&res=products%2F427897&et=1658500915&method=sha1&sign=%2FyqlRlNnYcvwy4dRZuJPMdUh004%3D'
          },
          success(res){
            that.FormatData(res.data.data.datastreams[0].datapoints,res.data.data.count)
          }
        })
    }, 
    FormatData(e, len){
        
        //console.log(e)
        //console.log(len)
        var index=0;
        var arr=[]
        var timer =e[0].at.substr(11,2)
        var date = e[0].at.substr(5,5)
        if(timer>='00' && timer< '12'){
            arr[index++]={timer:0,at:date,value:false,show:false}
            arr[index++]={timer:0,at:date,value:false,show:false}
        }else if(timer>='12' && timer< '17'){
            arr[index++]={timer:0,at:date,value:false,show:false}
        }else{}

        for(var i=0 ; i < len ;index++,i++){
              arr[index]={
                timer:e[i].at.substr(10,6),
                at:e[i].at.substr(5,5),
                value:e[i].value>"0"?true:false,
                show:true
              }
        }
        
        var i = 0, j = 0,k = 0;
            while(i<index){
                var temp =[
                    arr[i++],
                    arr[i++],
                    arr[i++]
                ]
                this.setData({
                  ["list["+ j++ +"]"]:temp
                })
            }
    }
})